<template>
  <div>
    <div class="dashboard-container">
      

      <div class="big-back-box">
        <div class="top">修改密码</div>
        <el-card
          class="box-card"
          style="width: 500px; margin: 0 auto; margin-top: 40px"
        >
          <div>新密码：</div>
          <div style="height: 20px"></div>
          <el-input
            placeholder="请输入新密码"
            v-model="newPwd"
            show-password
          ></el-input>
          <div style="height: 20px"></div>
          <div>确认新密码：</div>
          <div style="height: 20px"></div>
          <el-input
            placeholder="请输入新密码"
            v-model="confirmNewPwd"
            show-password
          ></el-input>
          <div style="height: 20px"></div>
          <el-button style="margin: 0 auto" @click="submitPwd">确定</el-button>
        </el-card>
      </div>
    </div>
  </div>
</template>

<script>
// 修改密码
import {changePassword} from '@/api/customerAccount.js'
// 引入获取当前登录账户信息用的
import { mapGetters } from "vuex";

export default {
  data() {
    return {
      newPwd: "",
      confirmNewPwd: ''
    };
  },
  // 获取全局变量相关，详见：src/store/getters.js
  computed: {
    ...mapGetters(["id", "name", "roles"]),
  },
  methods:{
    submitPwd(){
      // alert("this.id:"+this.id);
      if(this.confirmNewPwd != this.newPwd){
        alert("确认密码不一致，请重新输入！");
        return;
      }else{
        console.log("this.newPwd:"+this.newPwd);
        let dataNewPwd = {
          // id: // 在swagger UI上不传id也可以修改密码
          password: this.newPwd,
          // role: "buyer",// 在swagger UI上不传也可以修改密码
          // username: name,// 在swagger UI上不传也可以修改密码
        };
        changePassword(dataNewPwd).then((resp) => {
          console.log("resp.data.result:"+resp.data.result);
          console.log("resp.data.message:"+resp.data.message);
          alert("resp.data.message:"+resp.data.message);
          // 返回“我的账户”默认页面
          this.$router.push({path: '/customerCenter/customerAccount/displayPersonalInfo'});
        });
      }
    }
  },
}
</script>

<style lang="scss" scoped>
// 页头LOGO
.top {
  height: 50px;
  font-size: 30px;
  text-align: center;
  line-height: 50px;
}

// 大盒子
.big-back-box {
  width: 1080px;
  margin: 0 auto;
  // background-color: pink;
}

// 原框架自带
.dashboard {
  &-container {
    margin-top: 30px;
    // margin-left: 30px;
    // margin-right: 30px;
  }
  &-text {
    font-size: 30px;
    line-height: 46px;
  }
}

// 页脚
.footer {
  height: 300px;
  background-color: blue;
}
.footer-back-box {
  width: 1080px;
  margin-left: 45px;
}
.footer-title {
  height: 30px;
  line-height: 40px;
  padding-left: 10px;
}
.footer-link-card {
  width: 200px;
  background-color: orange;
  margin-left: 10px;
}
</style>